<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        #selectManager {
            width: 80%;
        }

        #find {
            background-color: #4D67F8;
        }
    </style>
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <script type="text/html" id="toolbarDemo">
                <div class="layui-inline">
                    <select name="quiz">
                        <option value="0">全部</option>
                        <optgroup label="按组织筛选">
                            <option value="1,1001,学生会">学生会</option>
                            <option value="1,1002,党办">党建办公室</option>
                            <option value="1,1003,就业">就业事务中心</option>
                            <option value="1,1004,学生事务">学生事务中心</option>
                        </optgroup>
                        <optgroup label="按审核状态">
                            <option value="2,2,已审核">已审核</option>
                            <option value="2,1,已提交材料">已提交材料</option>
                            <option value="2,0,未提交材料">未提交材料</option>
                        </optgroup>
                        <optgroup label="按类型筛选">
                            <option value="3,德育,">德育</option>
                            <option value="3,美育,">美育</option>
                            <option value="3,智育,">智育</option>
                            <option value="3,体育,">体育</option>
                            <option value="3,劳育,">劳育</option>
                        </optgroup>
                    </select>
                </div>
                <div class="layui-btn-container layui-inline">
                    <button type="submit" lay-submit lay-filter="data-search-btn" class="layui-btn layui-btn-sm"
                        id="find">
                        查询 </button>
                </div>
                <div class="layui-btn-container layui-inline">
                    <button class="layui-btn layui-btn-normal layui-btn-sm" style="background:none;margin-left: 15px;"
                        lay-submit lay-filter="charts" data-method="notice"> <img style="width:20px"
                            src="../images/statistic.png" alt="">
                    </button>
                </div>
                <div class="layui-btn-container layui-inline">
                    <button class="layui-btn layui-btn-normal layui-btn-sm" style="background:none;" lay-submit
                        lay-filter="charts2" data-method="notice2"> <img style="width:20px" src="../images/chartpie.png"
                            alt="">
                    </button>
                </div>
            </script>
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>
    </div>
    <script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../js/echarts.js" ,type="text/javascript"></script>
    <script>
        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;
            table.render({
                elem: '#currentTableId',
                url: '/showStudentData',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['exports', 'print'],
                cols: [
                    [{
                            type: "checkbox",
                            width: 0
                        },
                        {
                            field: 'a_no',
                            width: 110,
                            title: '活动编号',
                            sort: true
                        },
                        {
                            field: 'a_name',
                            title: '活动名称',
                            minWidth: 150,
                        },
                        {
                            field: 'm_name',
                            minWidth: 150,
                            title: '举办组织',
                            sort: true
                        },
                        {
                            field: 'type',
                            minWidth: 150,
                            title: '类型',
                            sort: true
                        },
                        {
                            field: 'e_time',
                            minWidth: 150,
                            title: '截止时间',
                            sort: true
                        },
                        {
                            field: 'time',
                            title: '参与时间',
                            minWidth: 150,
                            sort: true
                        },
                        {
                            field: 'status',
                            width: 150,
                            title: '参与状态',
                            sort: true
                        },
                        {
                            field: 'score',
                            width: 150,
                            title: '所得量化',
                            sort: true
                        }
                    ]
                ],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: true,
                skin: 'line'
            });
            var active2 = {
                notice: function () {
                    //示范一个公告层
                    layer.open({
                        type: 1,
                        title: false, //不显示标题栏
                        closeBtn: false,
                        area: '800px;',
                        shade: 0.8,
                        id: 'LAY_layuipro', //设定一个id，防止重复弹出
                        btn: ['关闭'],
                        btnAlign: 'c',
                        moveType: 1, //拖拽模式，0或者1
                        content: '<div id = "chart" style = "color:red;width:700px;height:400px;margin:0 auto;margin-top:35px;"></div>',
                        success: function (layero) {
                            var xdata = [];
                            var ydata = [];
                            var year = new Date().getFullYear();
                            var month = new Date().getMonth() + 1;
                            var text = ""
                            if (month >= 9)
                                text = year + "-" + (year + 1) + "学年每月量化统计";
                            else
                                text = (year - 1) + "-" + year + "学年每月量化统计";
                            $.get('/showStudentData', { //待修改
                                "function": "barchart"
                            }, function (re) {
                                if (re == '0') {
                                    layer.msg("加载失败");
                                } else {
                                    chart_data = re;
                                    if (month >= 9) {
                                        for (var i = 0; i < (month - 9) + 1; i++) {
                                            xdata[i] = year + '/' + (9 + i);
                                            ydata[i] = chart_data[(9 + i)];
                                        }
                                    } else {
                                        for (var i = 0; i < 4; i++) {
                                            xdata[i] = (year - 1) + '/' + (9 + i);
                                            ydata[i] = chart_data[(9 + i)];
                                        }
                                        for (var i = 4; i < (month + 4); i++) {
                                            xdata[i] = (year) + '/' + (i - 3);
                                            ydata[i] = chart_data[(i - 3)];
                                        }
                                    }
                                    var myChart = echarts.init(document
                                        .getElementById('chart'));
                                    myChart.setOption(option);
                                }
                            })
                            // 基于准备好的dom，初始化echarts实例
                            // 指定图表的配置项和数据
                            var option = {
                                title: {
                                    text: text,
                                    left: 'center'
                                },
                                tooltip: {},
                                legend: {
                                    data: ['累计量化']
                                },
                                xAxis: {
                                    data: xdata, //周次
                                    name: "月份"
                                },
                                yAxis: {
                                    name: "量化分数",
                                    minInterval: 1
                                },
                                series: [{
                                        type: 'bar',
                                        data: ydata
                                    },
                                    {
                                        type: 'line',
                                        data: ydata
                                    }
                                ]
                            };
                            // 使用刚指定的配置项和数据显示图表。

                        }
                    });
                }
            }
            form.on('submit(charts)', function () {
                var othis = $(this),
                    method = othis.data('method');
                active2[method] ? active2[method].call(this, othis) : '';
            })
            var active3 = {
                notice2: function () {
                    //示范一个公告层
                    layer.open({
                        type: 1,
                        title: false, //不显示标题栏
                        closeBtn: false,
                        area: '800px;',
                        shade: 0.8,
                        id: 'LAY_layuipro', //设定一个id，防止重复弹出
                        btn: ['关闭'],
                        btnAlign: 'c',
                        moveType: 1, //拖拽模式，0或者1
                        content: '<div id = "chart2" style = "color:red;width:700px;height:400px;margin:0 auto;margin-top:35px;"></div>',
                        success: function (layero) {
                            var data = [{}, {}, {}, {}, {}];
                            var year = new Date().getFullYear();
                            var month = new Date().getMonth() + 1;
                            var text = ""
                            if (month >= 9)
                                text = year + "-" + (year + 1) + "学年不同类型活动量化得分情况";
                            else
                                text = (year - 1) + "-" + year + "学年不同类型活动量化得分情况";
                            $.get('/showStudentData', { //待修改
                                "function": "piechart"
                            }, function (re) {
                                if (re == '0') {
                                    layer.msg("加载失败");
                                } else {
                                    data[0].name = '德育'
                                    data[0].value = re[data[0].name];
                                    data[1].name = '美育'
                                    data[1].value = re[data[1].name];
                                    data[2].name = '智育'
                                    data[2].value = re[data[2].name];
                                    data[3].name = '体育'
                                    data[3].value = re[data[3].name];
                                    data[4].name = '劳育'
                                    data[4].value = re[data[4].name];
                                    console.log(data);
                                    var myChart = echarts.init(document
                                        .getElementById('chart2'));
                                    myChart.setOption(option);
                                }
                            })
                            // 基于准备好的dom，初始化echarts实例

                            // 指定图表的配置项和数据
                            option = {
                                title: {
                                    text: text,
                                    left: 'center'
                                },
                                tooltip: {
                                    trigger: 'item'
                                },
                                legend: {
                                    orient: 'vertical',
                                    left: 'left'
                                },
                                series: [{
                                    name: 'Access From',
                                    type: 'pie',
                                    radius: '50%',
                                    data: data,
                                    emphasis: {
                                        itemStyle: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    }
                                }]
                            };
                            // 使用刚指定的配置项和数据显示图表。

                        }
                    });
                }
            }
            form.on('submit(charts2)', function () {
                var othis = $(this),
                    method = othis.data('method');
                active3[method] ? active3[method].call(this, othis) : '';
            })
            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var result = JSON.stringify(data.field.quiz);
                //执行搜索重载
                table.reload('currentTableId', {
                    page: {
                        curr: 1
                    },
                    where: {
                        searchParams: result
                    }
                }, 'data');
                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') { // 监听添加操作
                    var index = layer.open({
                        title: '添加用户',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: '../page/table/add.html',
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                } else if (obj.event === 'delete') { // 监听删除操作
                    var checkStatus = table.checkStatus('currentTableId'),
                        data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                }
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log(obj)
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {

                    var index = layer.open({
                        title: '编辑用户',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: '../page/table/edit.html',
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    return false;
                } else if (obj.event === 'delete') {
                    layer.confirm('真的删除行么', function (index) {
                        obj.del();
                        layer.close(index);
                    });
                }
            });

        });
    </script>

</body>

</html>